<?php
$oJobs = JobHandler::getJobs();
$oMissions = $oJobs[$_SESSION['iJobID']]->getMissions();
$oMissionLog = $oMissions[$_REQUEST['iMissionID']]->getLog();
$sMissionStatus = MissionHandler::getStatuses();
$sMissiongroups = $oJobs[$_SESSION['iJobID']]->getMissiongroups();
$oUsers = UserHandler::getUsers();
?>
<table cellspacing="0">
	<tr>
		<td style="padding: 0px 0px 0px 0px;">
			<table style="width: 100%;" cellspacing="0">
				<tr>
					<td class="listtop center"><?php print msg('Timing') ?></td>
					<td class="listtop center"><?php print msg('User') ?></td>
					<td class="listtop"><?php print msg('Action') ?></td>
					<td class="listtop"><?php print msg('Task') ?></td>
					<td class="listtop center"><?php print msg('Group') ?></td>
					<td class="listtop center"><?php print msg('Urgency') ?></td>
					<td class="listtop center"><?php print msg('Deadline') ?></td>
					<td class="listtop center"><?php print msg('Status') ?></td>
					<td class="listtop"><?php print msg('Assignment') ?></td>
				</tr>
<?php
$bLast = false; //For knowing when to stop underlining.
for ($i = 0; $i < count($oMissionLog); $i++)
{
	$oLog = $oMissionLog[$i];
	if ($i + 1 == count($oMissionLog))
	{
		$bLast = true;
	}
	
	switch ($oLog->sActiontype)
	{
		case 'change':
			$sHRActiontype = msg('Change');
			break;
		case 'create':
			$sHRActiontype = msg('Creation');
			break;
		default:
			$sHRActiontype = '['.msg('Undefined').']';
	}
	
	$iUsers = split('\|', trim($oLog->sUsers, '|'));
	$sUsers = '';
	for ($ii = 0; $ii < count($iUsers); $ii++)
	{
		if ($ii > 0)
		{
			$sUsers .= ', ';
		}
		
		$sUsers .= '<a href="viewuser.php?iUser='.$iUsers[$ii].'">'.$oUsers[$iUsers[$ii]]->sUser.'</a>';
	}
	?>
				<tr>
					<td class="listentity small vtop center"><?php print coolDate($oLog->iTiming) ?></td>
					<td class="listentity small vtop center"><a href="viewuser.php?iUser=<?php print $oLog->iUser ?>"><?php print $oUsers[$oLog->iUser]->sUser ?></a></td>
					<td class="listentity small vtop"><?php print $sHRActiontype ?></td>
					<td class="listentity small vtop"><?php print ($bLast || $oLog->sTodo == $oMissionLog[$i + 1]->sTodo ? htmlspecialchars($oLog->sTodo) : '<span class="emphasize">'.htmlspecialchars($oLog->sTodo).'</span>') ?></td>
					<td class="listentity small vtop center"><?php print ($bLast || $oLog->iGroup == $oMissionLog[$i + 1]->iGroup ? @$sMissiongroups[$oLog->iGroup] : '<span class="emphasize">'.$sMissiongroups[$oLog->iGroup].'</span>') ?></td>
					<td class="listentity small vtop center"><?php print ($bLast || $oLog->iUrgency == $oMissionLog[$i + 1]->iUrgency ? $oJobs[$_SESSION['iJobID']]->sUrgencies[$oLog->iUrgency] : '<span class="emphasize">'.$oJobs[$_SESSION['iJobID']]->sUrgencies[$oLog->iUrgency].'</span>') ?></td>
					<td class="listentity small vtop center"><?php print ($bLast || $oLog->iFinishTime == $oMissionLog[$i + 1]->iFinishTime ? coolDate($oLog->iFinishTime) : '<span class="emphasize">'.coolDate($oLog->iFinishTime).'</span>') ?>&nbsp;</td>
					<td class="missionstatus<?php print $oLog->iStatus ?> small center vtop"><?php print ($bLast || $oLog->iStatus == $oMissionLog[$i + 1]->iStatus ? $sMissionStatus[$oLog->iStatus]['caption'] : '<span class="emphasize">'.$sMissionStatus[$oLog->iStatus]['caption']) ?></td>
					<td class="listentity small vtop center"><?php print ($bLast || trim($oLog->sUsers, '|') == trim($oMissionLog[$i + 1]->sUsers, '|') ? $sUsers : '<span class="emphasize">'.$sUsers.'</span>') ?>&nbsp;</td>
				</tr>
	<?php
}
?>
			</table>
		</td>
	</tr>
	<tr>
		<td class="boxbody center">
			<input type="button" value="<?php print msg('Close') ?>" onClick="layerHide('layer_mission_show');">
		</td>
	</tr>
</table>
